# -*- coding: utf-8 -*-
# @Time    : 2020/3/17 23:59
# @Author  : seelingzheng
# @公众号  : seeling_gis
# @File    : importshp.py
# @Software: PyCharm

from  iobjectspy.conversion import  import_shape
  
import os,sys
from os import  path


shp_dir = r'F:\gisdata\实验数据\丰台gdb\output\样例'

udb_dir = r'F:\gisdata\实验数据\丰台gdb\test.UDB'



def loop_file(file):
    files = os.listdir(file)
    for f in files:
        new_file =  file + os.sep + f
        print (new_file)
        if path.isdir(new_file):
            loop_file(new_file)
        elif  path.split(new_file)[1][-3:] == 'shp':
            print(new_file+'*'*4)
            shp_udb(new_file)


def shp_udb(f):
    # ds = Datasource.create(':memory:')
    # alias = ds.alias

    result = import_shape(f,udb_dir,progress=progress_func)
    print_info(result)

def print_info(result):
    if result is not None:
        for item in result:
            name = item
            if not isinstance(item, str):
                name = item.name
            sys.stdout.write('导入数据成功，导入到数据集 %s\n'% name)

def progress_func(step_event):
    sys.stdout.write('%s, %s %% \n'.format(step_event.title,step_event.message))

if __name__ == '__main__':
    loop_file(shp_dir)






